type MType = { [k: number]: number[] };
function findShortestSubArray(nums: number[]): number {
  const m: Map<number, [number, number, number]> = new Map();
  for (let i = 0; i< nums.length; i++) {
    if (m.has(nums[i])) {
      m.get(nums[i])[0]++;
      m.get(nums[i])[2] = i;
    } else {
      m.set(nums[i], [1, i, i]);
    }
  }
  let maxNum = 0, minLen = 0;
  for (let [count, left, right] of m.values()) {
    const len = right - left + 1;
    if (maxNum < count) {
      maxNum = count;
      minLen = len;
    } else if (maxNum === count) {
      if (minLen > len) minLen = len;
    }
  }
  return minLen;
};